package com.cuile.littletools

import android.content.pm.PackageManager
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat

/**
 * Created by cuile on 18-10-31.
 *
 */
abstract class BaseActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setTheme(R.style.AppTheme)
        initCreateActivity(savedInstanceState)
    }

    abstract fun initCreateActivity(savedInstanceState: Bundle?)


    fun requestPermission(permission: String, requestCode: Int, op: () -> Unit) {
        if (ContextCompat.checkSelfPermission(this, permission)
                != PackageManager.PERMISSION_GRANTED) {

            if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {

            } else {
                ActivityCompat.requestPermissions(this, arrayOf(permission), requestCode)
            }

        } else {
            op()
        }
    }


}